﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Xunit;

namespace dogd.Tests
{
	[Table("Stored")]
	public class StorableClass
	{
		[Column("StorageID")]
		public int DbKey
		{
			get;
			set;
		}

		[LookupColumn("StoredName")]
		public string Name
		{
			get;
			set;
		}

		[Column("StoredValue")]
		public int Value
		{
			get;
			set;
		}
	}

	public class MetadataProviderFacts
	{
		public class TheLoadDataForMethod
		{
			[Fact]
			public void WillLoadDataForPersistableClass()
			{
				var provider = new MetadataProvider();

				var table = provider.LoadDataFor(typeof(StorableClass));

				Assert.NotNull(table);
			}

			[Fact]
			public void ThrowsExceptionIfClassIsUnpersistable()
			{
				var provider = new MetadataProvider();

				Assert.Throws<ArgumentException>(() =>
						provider.LoadDataFor(
							typeof(StringBuilder)));
			}
		}

		public class TheNameProperty
		{
			[Fact]
			public void IdentifiesTheTableNameFromAttribute()
			{
				var provider = new MetadataProvider();

				var table = provider.LoadDataFor(typeof(StorableClass));

				Assert.Equal("Stored", table.Name);
			}
		}

		public class TheColumnsCollection
		{
			[Fact]
			public void IdentifiesTheColumnsFromAttributes()
			{
				var provider = new MetadataProvider();

				var table = provider.LoadDataFor(typeof(StorableClass));

				Assert.Equal(3, table.Columns.Count);
			}
		}

	}
}
